package cn.shop.cloud.web.advice;

import cn.shop.cloud.common.CommonControllerAdvice;
import cn.shop.cloud.common.Result;
import cn.shop.cloud.web.msg.MemberCodeMsg;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: shop-parent
 * @ClassName MemberServerControllerAdvice
 * @description:
 * @author: Mokio
 * @create: 2024−12-24 15:16
 * @Version 2024 2.2 ; jdk1.8.0_181
 **/
public class MemberServerControllerAdvice extends CommonControllerAdvice {

    // 自定义当前项目的异常
    // 自定义个der就是把捕获到的系统异常返回给前端了
    @ExceptionHandler(BindException.class)
    @ResponseBody
    public Result handlerBindException(BindException ex) {
        String msg = ex.getAllErrors().get(0).getDefaultMessage();

        return Result.error(MemberCodeMsg.PARAM_ERROR.fillArgs(msg));
    }
}
